package org.example.mq.demo;

import org.example.mq.brokerserver.core.ExchangeType;
import org.example.mq.client.Channel;
import org.example.mq.client.Connection;
import org.example.mq.client.ConnectionFactory;

import java.io.IOException;

public class DemoProducer {
    public static void main(String[] args) throws IOException, InterruptedException {
        System.out.println("[DemoProducer] 启动生产者！");
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("127.0.0.1");
        factory.setPort(9090);

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        //创建交换机和队列
        channel.exchangeDeclare("testExchange", ExchangeType.DIRECT,true,false,null);
        channel.queueDeclare("testQueue",true,false,false,null);

        //创建消息并发送
        byte[] body = "hello word!".getBytes();
        boolean ok = channel.basicPublish("testExchange","testQueue",null,body);
        System.out.println("[DemoProducer] 消息投递完成！");

        Thread.sleep(200);
        channel.close();
        connection.close();
    }
}
